import React, { Component, createRef } from "react";

// 非受控组件
// 使用createRef去创建内存，获取dom节点
class App extends Component {
  // constructor() {
  //   super();
  //   this.ipt = createRef();
  // }

  ipt = createRef();
  ipt2 = createRef();

  fn = () => {
    console.log(this.ipt.current.value);
    console.log(this.ipt2.current.value);
  };

  render() {
    return (
      <>
        <h2>非受控组件</h2>
        {/* 非受控组件的默认值要用defaultValue */}
        <input type="text" ref={this.ipt} defaultValue="4555" />
        <input type="text" ref={this.ipt2} />
        <button onClick={this.fn}>btn</button>
      </>
    );
  }
}

export default App;
